package com.jk.dao;

import com.jk.Util.DynamicSql;
import com.jk.pojo.PayLog;
import com.jk.pojo.PayShopsCoupon;
import com.jk.pojo.PayUser;
import com.jk.pojo.PayUserCoupon;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * 用户优惠券dao层接口
 * Created by Administrator on 2017/12/20 0020.
 */
public interface PayUserCouponDao {
        //调用sql工具类中的对应查询方法进行查询用户共有多少张可用的优惠券
        @SelectProvider(type = DynamicSql.class,method = "queryPayUserCouponCount")
        int queryPayUserCouponCount(String userid);

        //根据用户id查询出用户可用优惠券的总条数
        @SelectProvider(type = DynamicSql.class,method = "queryPayShopsCouponCount")
        int queryPayShopsCouponCount(String userid);

        //根据用户id查询出用户可用优惠券的具体信息
        @SelectProvider(type = DynamicSql.class,method = "queryPayShopsCouponList")
        List<Map<String,Object>> queryPayShopsCouponList(@Param("userid") String userid, @Param("start") int start, @Param("rows") int rows);

        //根据优惠券id查询具体的优惠券信息
        @SelectProvider(type = DynamicSql.class,method = "queryPayShopsCoupon")
        PayShopsCoupon queryPayShopsCoupon(String couponid);

        //根据优惠券id查询用户是否拥有该优惠券
        @SelectProvider(type = DynamicSql.class,method = "queryPayUserCouponCountByCouponId")
        int queryPayUserCouponCountByCouponId(String couponid);

        //将用户领取的优惠券添加到用户优惠券表中
        @InsertProvider(type = DynamicSql.class,method = "insertPayUserCoupon")
        int insertPayUserCoupon(PayUserCoupon payUserCoupon);

        //查询出用户优惠券的主键id和过期时间
        @SelectProvider(type = DynamicSql.class,method = "queryPayUserCouponOverdueTime")
        List<PayUserCoupon> queryPayUserCouponOverdueTime();

        //根据优惠券id删除用户过期的优惠券
        @DeleteProvider(type = DynamicSql.class,method = "deletePayUserCouponStart")
        void deletePayUserCouponStart(String ucid);

        //根据优惠券id删除商家过期的优惠券
        @DeleteProvider(type = DynamicSql.class,method = "deletePayShopsCouponStart")
        void deletePayShopsCouponStart(String couponid);

        //查询商家优惠券主键id和过期时间
        @SelectProvider(type = DynamicSql.class,method = "queryPayShopsCouponStartOverdueTime")
        List<PayShopsCoupon> queryPayShopsCouponStartOverdueTime();

        //根据用户id修改用户余额
        @UpdateProvider(type = DynamicSql.class,method = "updateUserBalance")
        int updateUserBalance(@Param("goodCommodityPrice") Double goodCommodityPrice,@Param("userid") String userid);

        //根据用户优惠券主键id修改此优惠券状态为已使用
        @UpdateProvider(type = DynamicSql.class,method = "updateUserCouponStauts")
        void updateUserCouponStauts(String ucid);

        //根据用户id查询出用户余额
        @SelectProvider(type = DynamicSql.class,method = "queryUserUserBalance")
        PayUser queryUserUserBalance(String userid);

        //根据用户id修改用户余额
        @UpdateProvider(type = DynamicSql.class,method = "updateUserIntegral")
        int updateUserIntegral(@Param("integral") int integral,@Param("userid") String userid);

        //查询用户优惠券状态
        @SelectProvider(type = DynamicSql.class,method = "queryPayUserCouponStatus")
        PayUserCoupon queryPayUserCouponStatus(String ucid);

        //新增消费记录信息
        @InsertProvider(type = DynamicSql.class,method = "insertPayUserCouponLog")
        int insertPayUserCouponLog(PayLog log);

        //用户领取优惠券以后将商家优惠券领取数量加一
        @UpdateProvider(type = DynamicSql.class,method = "updatePayShopsCouponGetCount")
        int updatePayShopsCouponGetCount(String couponid);

        //添加商家优惠券
        @InsertProvider(type = DynamicSql.class,method = "insertPayShopsCoupon")
        int insertPayShopsCoupon(PayShopsCoupon payShopsCoupon);

        @SelectProvider(type = DynamicSql.class,method = "queryShopsCouponListAll")
        List<Map<String,Object>> queryShopsCouponListAll();

        @Select("select p1.ucId,p2.shopId from pay_user_coupon p1,pay_shops_coupon p2 where p1.couponId = p2.couponId " +
                " AND p2.couponId = #{coid}")
        List<Map<String,Object>> queryPayShopsUserCoupon(String coid);
}
